# myMail.py
# 发送测试邮件
import smtplib
from email.header import Header
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

#服务器设置
smtp_server = 'smtp.126.com'
from_addr = 'jerry6824@126.com'
password = '1qaz2wsx'

to_addr = input('To: ')

#邮件设置
heading = 'For my friend'
main_body_html = '<html>'+\
             '<body>'+\
             '<h1>hello, friend</h1>'+\
             '<p><img src="cid:0"></p>'+\
             '</body>'+\
             '</html>'
msg = MIMEMultipart('alternative')
msg['From'] = from_addr
msg['To'] = to_addr
msg['Subject'] = Header(heading, 'utf-8').encode()
msg.attach(MIMEText(main_body_html, 'html', 'utf-8'))

#发送邮件
server = smtplib.SMTP(smtp_server, 25)
server.set_debuglevel(1)
server.connect(smtp_server, 25)
server.helo()
server.ehlo()
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()
